//
//  TQNerworkRequest.m
//  项目一_谭倩
//
//  Created by dandan on 16/2/29.
//  Copyright © 2016年 dandan. All rights reserved.
//

#import "TQNerworkTool.h"

@interface TQNetworkTool()

@end

@implementation TQNetworkTool

+(TQNetworkTool *)sharedNetWorkingTool
{
    static TQNetworkTool *networkingTool;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        networkingTool=[[self alloc]init];
        networkingTool.responseSerializer.acceptableContentTypes=[NSSet setWithObjects:@"text/html", nil];
        //设置请求的参数  json,根据文档提供的参数传递模式来确定需要请求的格式
        networkingTool.requestSerializer.timeoutInterval = 10.f;
        //返回结果 text/HTML
        
//                networkingTool.responseSerializer = [AFHTTPResponseSerializer serializer];
    });
    return networkingTool;
}



- (void)requestURL:(NSString *)url withParams:(NSMutableDictionary *)params fileData:(NSMutableDictionary*)fileDic finished:(void (^)(id, NSError *))finished
{

    
    [self POST:url parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        if(fileDic){
            [formData appendPartWithFileData:fileDic[@"data"]
                                        name:fileDic[@"nameKey"]
                                    fileName:fileDic[@"fileName"]
                                    mimeType:fileDic[@"fileType"]];
        }
      
        
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        NSLog(@"%@",uploadProgress);
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        finished(responseObject,nil);
        NSLog(@"%@",responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        finished(nil,error);
        NSLog(@"%@",error);
    }];
}



@end
